﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Volo.Abp.Application.Dtos
{
    public class ResultDto<T>
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; protected set; }
        /// <summary>
        /// 错误码
        /// </summary>
        public string ErrorCode { get; protected set; }
        /// <summary>
        /// 错误消息
        /// </summary>
        public string ErrorMsg { get; protected set; }
        /// <summary>
        /// 数据
        /// </summary>
        public T Data { get; protected set; }

        /// <summary>
        /// 能使用的列
        /// </summary>
        public List<Header > Headers { get; set; }

        /// <summary>
        /// 返回成功的消息体
        /// </summary>
        /// <param name="data"></param>
        /// <param name="success"></param>
        public ResultDto(T data, bool success = true)
        {
            Success = success;
            Data = data;
        }
        /// <summary>
        /// 返回失败的消息
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="errorCode"></param>
        /// <param name="success"></param>
        public ResultDto(string errorMsg, string errorCode = "", bool success = false)
        {
            Success = success;
            ErrorCode = errorCode;
            ErrorMsg = errorMsg;
        }
    }
    /// <summary>
    /// 分页返回
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PageResultDto<T> : ResultDto<IEnumerable<T>>
    {
        /// <summary>
        /// 数据总数量
        /// </summary>
        public long Count { get; protected set; }
        /// <summary>
        /// 返回成功的消息体
        /// </summary>
        /// <param name="data"></param>
        /// <param name="success"></param>
        public PageResultDto(IEnumerable<T> data, long count = -1, bool success = true) : base(data, success)
        {
            Count = count;
        }
        /// <summary>
        /// 返回失败的消息
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="errorCode"></param>
        /// <param name="success"></param>
        public PageResultDto(string errorMsg, string errorCode = "", bool success = false)
                   : base(errorMsg, errorCode, success)
        {
        }
    }


    /// <summary>
    /// 分页返回
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PageDataResultDto<T> : ResultDto<T>
    {
        /// <summary>
        /// 数据总数量
        /// </summary>
        public long Count { get; protected set; }
        /// <summary>
        /// 返回成功的消息体
        /// </summary>
        /// <param name="data"></param>
        /// <param name="success"></param>
        public PageDataResultDto(T data, long count = -1, bool success = true) : base(data, success)
        {
            Count = count;
        }
        /// <summary>
        /// 返回失败的消息
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="errorCode"></param>
        /// <param name="success"></param>
        public PageDataResultDto(string errorMsg, string errorCode = "", bool success = false)
                   : base(errorMsg, errorCode, success)
        {
        }
    }

    public class Header
    {
        public string Code { get; set; }
        public List<Header> Childrens { get; set; }
    }

}
